package com.soledroid;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.provider.Settings.Secure;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;
import com.soledroid.Model.Stall;


public class CanteenOverlay extends BalloonItemizedOverlay<OverlayItem> {
	private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
	private Context mContext;
	
	public CanteenOverlay(Drawable defaultMarker, MapView mapView) {
		super(boundCenter(defaultMarker), mapView);
		mContext = mapView.getContext();
	}

	@Override
	protected OverlayItem createItem(int i) {
		return mOverlays.get(i);
	}

	@Override
	public int size() {
		return mOverlays.size();
	}
	
	@Override
	public void draw(Canvas canvas, MapView mapView, boolean shadow) { 
		super.draw(canvas, mapView, false);
	}
	
	@Override
	protected boolean onBalloonTap(int index, OverlayItem item) {
		Intent Details = new Intent(mContext, CanteenActivity.class); 
        Details.putExtra("id", Integer.parseInt(mOverlays.get(index).getSnippet()));
        Details.putExtra("name", mOverlays.get(index).getTitle());
        mContext.startActivity(Details); 
		return true;
	}
	
	public void addOverlay(OverlayItem overlay) {
	    mOverlays.add(overlay);
	    populate();
	}
	
	public void clear() {
		mOverlays.clear();
		//populate();
	}
	
}
